package com.hu.web.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class SixthServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("SixthServlet 的 doGet 方法执行");

        // 添加响应头
//        response.addHeader("Content-Type","text/html;charset=utf-8");
//        response.setContentType("text/html;charset=utf-8");

        // 通过输出流将响应数据输出给客户端
//        PrintWriter writer = response.getWriter();
//        writer.write("<h1 style='color:red;'>响应成功</h1>");
//        writer.write("<h2 style='color:red;'>养天地正气,法古今完人</h2>");

        String id = request.getParameter("id");
        String name = request.getParameter("name");
        System.out.println("SixthServlet: id=" + id + ",name=" + name);
        request.setAttribute("requestMsg", "request共享的数据");

        // 重定向到 SeventhServlet
//        response.sendRedirect("seventh");
        // 重定向到页面
//        response.sendRedirect("success.html");

        // 不能访问
//        response.sendRedirect("WEB-INF/root.html");
        // 可以访问
        request.getRequestDispatcher("WEB-INF/root.html").forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

}
